<template>
  <view class="my-container">
    <view class="my-avatar_uname">
      <image class="avatar" :src="userInfo.avatarUrl"></image>
      <text class="uname">{{userInfo.nickName}}</text>
    </view>

    <!-- 面板列表 -->
    <view class=".pannel-list">
      <!-- 收藏 关注 足迹 -->
      <view class="pannel">
        <view class="pannel-body">
          <!-- 收藏的店铺 -->
          <view class="pannel-item">
            <text>8</text>
            <text>收藏的店铺</text>
          </view>
          <!-- 收藏的商品 -->
          <view class="pannel-item">
            <text>14</text>
            <text>收藏的商品</text>
          </view>
          <!-- 关注的商品 -->
          <view class="pannel-item">
            <text>18</text>
            <text>关注的商品</text>
          </view>
          <!-- 足迹 -->
          <view class="pannel-item">
            <text>84</text>
            <text>足迹</text>
          </view>
        </view>
      </view>

      <!-- 订单 -->
      <view class="pannel">
        <view class="pannel-title">我的订单</view>
        <view class="pannel-body">
          <!-- 待付款 -->
          <view class="pannel-item">
            <image class="item-icon" src="../../static/my-icons/icon1.png"></image>
            <text>待付款</text>
          </view>
          <!-- 待收货 -->
          <view class="pannel-item">
            <image class="item-icon" src="../../static/my-icons/icon2.png"></image>
            <text>待收货</text>
          </view>
          <!-- 退款|货 -->
          <view class="pannel-item">
            <image class="item-icon" src="../../static/my-icons/icon3.png"></image>
            <text>退款/退货</text>
          </view>
          <!-- 全部订单 -->
          <view class="pannel-item">
            <image class="item-icon" src="../../static/my-icons/icon4.png"></image>
            <text>全部订单</text>
          </view>
        </view>
      </view>

      <!-- 地址 客服 退出 -->
      <view class="pannel">
        <!-- 收货地址 -->
        <view class="pannel-info">
          <text>收货地址</text>
          <uni-icons type="forward" size="15"></uni-icons>
        </view>
        <!-- 联系客服 -->
        <view class="pannel-info">
          <text>联系客服</text>
          <uni-icons type="forward" size="15"></uni-icons>
        </view>
        <!-- 退出登录 -->
        <view class="pannel-info" @click="logOut">
          <text>退出登录</text>
          <uni-icons type="forward" size="15"></uni-icons>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    name: "my-userinfo",
    data() {
      return {

      };
    },

    computed: {
      ...mapState('m_user', ['userInfo'])
    },
    
    methods: {
      ...mapMutations('m_user', ['updateAddress', 'updateUserInfo', 'updateToken']),
      
      // 需要清空 vuex 中的 userinfo、token 和 address
      async logOut () {
        const [err, succ] = await uni.showModal({
          title: '提示',
          content: '确认退出登录吗？',
        }).catch(err => err)
        // console.log(succ)
        if (succ && succ.confirm) { 
          this.updateAddress({})
          this.updateUserInfo({})
          this.updateToken('')
        }
      },
    }
  }
</script>

<style lang="scss">
  .my-container {
    height: 100%;
    background-color: #f4f4f4;
    ;

    .my-avatar_uname {
      display: flex;
      height: 400rpx;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      background-color: #c00000;

      .avatar {
        display: block;
        width: 90px;
        height: 90px;
        margin-bottom: 10px;
        border-radius: 45px;
        border: 2px solid white;
        box-shadow: 0 1px 5px black;
      }

      .uname {
        font-size: 16px;
        font-weight: bold;
      }
    }
  }

  .pannel-list {
    padding: 0 10px;
    position: relative;
    top: -10px;

    .pannel {
      border-radius: 3px;
      margin-bottom: 8px;
      background-color: white;

      .pannel-title {
        height: 45px;
        line-height: 45px;
        padding-left: 10px;
        font-size: 15px;
        border-bottom: 1px solid #f4f4f4;
      }

      .pannel-body {
        display: flex;
        justify-content: space-around;

        .pannel-item {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: space-around;
          font-size: 13px;
          padding: 10px 0;

          .item-icon {
            width: 35px;
            height: 35px;
          }
        }
      }
      
      .pannel-info {
         height: 45px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          font-size: 15px;
          padding: 0 10px;
      }
    }
  }
</style>
